﻿<template>
    <div>
        <el-form ref="adduserref" :model="daylog" label-width="100px">
            <el-row>
                <el-col :span="9" :offset="2">
                    <el-form-item label="日期" prop="JournalDate">
                        <el-date-picker style="width: 100%" placeholder=""
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        v-model="daylog.JournalDate"></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="9" :offset="1">
                    <el-form-item label="班组" prop="Team">
                        <el-input v-model="daylog.Team"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="9" :offset="2">
                    <el-form-item label="天气" prop="Weather">
                        <el-input v-model="daylog.Weather"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="9" :offset="1">
                    <el-form-item label="风力" prop="WindPower">
                        <el-input v-model="daylog.WindPower"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="9" :offset="2">
                    <el-form-item label="最高温度" prop="MaxTemperature">
                        <el-input v-model="daylog.MaxTemperature"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="9" :offset="1">
                    <el-form-item label="最低温度" prop="MinTemperature">
                        <el-input v-model="daylog.MinTemperature"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="20" :offset="2">
                    <el-form-item label="工作情况" prop="ConstructionCondition">
                        <el-input type="textarea"
                                  v-model="daylog.ConstructionCondition"
                                  placeholder="施工日志：施工情况记录：（施工部位、施工内容、机械使用情况、劳动力情况，施工中存在的问题）
研发日志：研发情况记录：（研发情况、进展概述、人员工作情况，研发中存在的问题）
产品生产日志：产品生产情况记录。"
                                  :autosize="{ minRows: 6, maxRows: 10 }"
                                  :rows="6"
                                  show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="20" :offset="2">
                    <el-form-item label="材料情况" prop="MaterialInformation">
                        <el-input type="textarea"
                                  placeholder="今日材料使用情况"
                                  v-model="daylog.MaterialInformation"
                                  :rows="5"
                                  show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="20" :offset="2">
                    <el-form-item label="工作记录" prop="WorkRecord">
                        <el-input type="textarea"
                                  placeholder="技术、质量、安全工作记录：（技术、质量安全活动、检查验收、技术质量安全问题等)"
                                  v-model="daylog.WorkRecord"
                                  :rows="5"
                                  show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="20" :offset="2">
                    <el-divider content-position="center">人员考勤</el-divider>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="9" :offset="2">
                    <el-form-item label="出勤人员" prop="JournalDate">
                        <el-select v-model="PeoplesAll" multiple placeholder="请选择" style="width:100%">
                            <el-option v-for="(item,index) in AllProjectPeople"
                                       filterable
                                       :key="index"
                                       :label="item.UserName"
                                       :value="item.Id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="9" :offset="1">
                    <el-form-item label="出勤类型" prop="Team">
                        <el-radio v-model="radio1" border label="0">全天</el-radio>
                        <el-radio v-model="radio1" border label="1" disabled>上午</el-radio>
                        <el-radio v-model="radio1" border label="2" disabled>下午</el-radio>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="9" :offset="2">
                    <el-form-item label="出勤人员" prop="JournalDate">
                        <el-select v-model="PeoplesAM" multiple placeholder="请选择" style="width:100%">
                            <el-option v-for="(item,index) in AllProjectPeople"
                                       filterable
                                       :key="index"
                                       :label="item.UserName"
                                       :value="item.Id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="9" :offset="1">
                    <el-form-item label="出勤类型" prop="Team">
                        <el-radio v-model="radio2" border label="0" disabled>全天</el-radio>
                        <el-radio v-model="radio2" border label="1">上午</el-radio>
                        <el-radio v-model="radio2" border label="2" disabled>下午</el-radio>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="9" :offset="2">
                    <el-form-item label="出勤人员" prop="JournalDate">
                        <el-select v-model="PeoplesPM" multiple placeholder="请选择" style="width:100%">
                            <el-option v-for="(item,index) in AllProjectPeople"
                                       filterable
                                       :key="index"
                                       :label="item.UserName"
                                       :value="item.Id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="9" :offset="1">
                    <el-form-item label="出勤类型" prop="Team">
                        <el-radio v-model="radio3" border label="0" disabled>全天</el-radio>
                        <el-radio v-model="radio3" border label="1" disabled>上午</el-radio>
                        <el-radio v-model="radio3" border label="2">下午</el-radio>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="20" :offset="2">
                    <el-divider content-position="center">工程进度</el-divider>
                </el-col>
            </el-row>
            <el-row v-for="(itemplan,i) in addWorkPlanList">
                <el-col :span="9" :offset="2">
                    <el-form-item label="项目工序" prop="WorkPlanId">
                        <el-select v-model="itemplan.WorkPlanId" placeholder="请选择" style="width:100%">
                            <el-option v-for="(item,index) in AllProjectWorkPlan"
                                       filterable
                                       :key="index"
                                       :label="item.ConstructionProcedure"
                                       :value="item.Id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="9" :offset="1">
                    <el-form-item label="工程完成量" prop="Quantity">
                        <el-input v-model.trim="itemplan.Quantity"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="1">
                    <el-button v-if="i==0" style="margin-left:20px" icon="el-icon-plus" @click="AddWorkPlan" circle></el-button>
                    <el-button v-else style="margin-left:20px" icon="el-icon-delete" @click="DeleteWorkPlan(i)" circle></el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="20" :offset="2">
                    <el-divider content-position="center">设备台账</el-divider>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="19" :offset="2">
                    <el-form-item label="设备台账">
                        <el-select v-model="ProjectDevice" style="width: 100%" multiple>
                            <el-option v-for="v in AllProjectDevice" :value="v.Id" :label="v.DeviceName"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="20" :offset="2">
                    <el-divider content-position="center">工具台账</el-divider>
                </el-col>
            </el-row>
            <el-row v-for="(item,i) in ToolUseRecordList">
                <el-col :span="9" :offset="2">
                    <el-form-item label="工具名称">
                        <el-input v-model="item.ToolName"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="9" :offset="1">
                    <el-form-item label="借用人">
                        <el-select v-model="item.Borrower" style="width: 100%">
                            <el-option v-for="v in AllProjectPeople" :value="v.Id" :label="v.UserName"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="1">
                    <el-button v-if="i==0" style="margin-left:20px" icon="el-icon-plus" @click="AddWorkDevice" circle></el-button>
                    <el-button v-else style="margin-left:20px" icon="el-icon-delete" @click="DeleteWorkDevice(i)" circle></el-button>
                </el-col>
            </el-row>
            <el-row class="btns" >
                <el-col align="center">
                    <el-button type="primary" @click="AddSubmit">添加</el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
    import * as publicjs from "../../../public/Scriput/Public";
    export default {
        name: "AddProjectJournal",//添加项目日志
        props: {
            project: {
                type: Object,
                required: true,
            },
        },
        data() {
            return {
                daylog: {},
                AllProjectPeople: [],
                radio1: "0",
                radio2: "1",
                radio3: "2",
                addWorkPlanList: [
                    { Quantity:'', WorkPlanId:'',ProjectId:this.project.Id }
                ],
                ToolUseRecordList: [
                    { ToolName:'', Borrower:'',ProjectId:this.project.Id }
                ],
                AllProjectWorkPlan:[],
                AllProjectDevice:[],
                PeoplesAM:[],
                PeoplesPM:[],
                PeoplesAll:[],
                ProjectDevice:[],
            }
        },
        watch: {
            project: function (val) {
                this.GetProjectPeople()
                this.GetProjectWorkPlan()
                this.GetProjectDevice()
            }
        },
        mounted() {
            let _this = this
            _this.$nextTick(() => {
                _this.GetProjectPeople()
                _this.GetProjectWorkPlan()
                _this.GetProjectDevice()
            })
        },
        methods: {
            GetProjectPeople() {
                this.AllProjectPeople = publicjs.GetProjectPeople(this.$http, this.project.Id);
            },
            GetProjectWorkPlan() {
                this.AllProjectWorkPlan = publicjs.GetProjectWorkPlan(this.$http, this.project.Id);
            },
            GetProjectDevice() {
                this.AllProjectDevice = publicjs.GetProjectDevice(this.$http, this.project.Id);
            },
            //添加工程进度
            AddWorkPlan() {
                this.addWorkPlanList.push( { Quantity:'', WorkPlanId: '',ProjectId:this.project.Id } );
            },
            //删除工程进度
            DeleteWorkPlan(number) {
                this.addWorkPlanList.splice(number, 1);
            },
            //添加工具台账
            AddWorkDevice(){
                this.ToolUseRecordList.push( { ToolName:'', Borrower:'',ProjectId:this.project.Id })
            },
            //删除工程台账
            DeleteWorkDevice(number) {
                this.addWorkPlanList.splice(number, 1);
            },
            //新增项目日志使用台账
            AddSubmit() {
                for (let i=0; i<this.addWorkPlanList.length;i++) {
                    if (this.addWorkPlanList[i].WorkPlanId  == '' && this.addWorkPlanList[i].Quantity.length>0) {
                        this.$message.warning('请完善项目工序选项!')
                        return
                    }
                }
                this.daylog.ProjectId = this.project.Id
                let PeoplesAll_ = this.PeoplesAll.toString()
                let PeoplesPM_ = this.PeoplesPM.toString()
                let PeoplesAM_ = this.PeoplesAM.toString()
                let ProjectDevice_ = this.ProjectDevice.toString()
                for (let i=0; i<this.addWorkPlanList.length;i++) {
                    if (this.addWorkPlanList[i].WorkPlanId == '' && this.addWorkPlanList[i].Quantity == '') {
                        this.addWorkPlanList.splice(i,1)
                    }else{
                        this.addWorkPlanList[i].WorkPlanId = this.addWorkPlanList[i].WorkPlanId.toString()
                    }
                }
                for (let i=0; i<this.ToolUseRecordList.length;i++) {
                    if (this.ToolUseRecordList[i].Borrower=='') {
                        this.ToolUseRecordList.splice(i,1)
                    }
                }
                this.$http.post('Project1/AddProjectJournal',{
                    projectJournal: this.daylog,
                    PeoplesAll: PeoplesAll_,
                    PeoplesAM: PeoplesAM_,
                    PeoplesPM: PeoplesPM_,
                    ProjectDevice: ProjectDevice_,
                    projectWorkProgresslis: this.addWorkPlanList,
                    ProjectToolUseRecordlis: this.ToolUseRecordList,
                }).then(res=>{
                    if (res.data.result.IsSuccess){
                        this.$message.success(res.data.result.Msg)
                        this.$parent.$parent.ProjectTable(res.data.data,'first')
                        this.$refs['adduserref'].resetFields()
                        this.$parent.$parent.AddProjectJournal_dialog.show=false
                    }else{
                        this.$message.warning(res.data.result.Msg)
                    }
                })
            },
            //关闭后的回调
            DialogCloseEvent(){
                this.$refs['adduserref'].resetFields()
                this.PeoplesAM = []
                this.PeoplesPM = []
                this.PeoplesAll = []
                this.addWorkPlanList = [ { Quantity:'', WorkPlanId:'',ProjectId:this.project.Id } ]
                this.ToolUseRecordList = [ { ToolName:'', Borrower:'',ProjectId:this.project.Id } ]
            }
        },
    }
</script>

<style scoped>
</style>
